<template>
    <div v-loading="loading">
        <el-card>
            <template #header>
                <div>
                    问卷管理
                    <el-button type="text" @click="$router.push({ name: 'PapersAdd' })">
                        添加问卷
                    </el-button>
                </div>
            </template>
            <el-table :data="papers" border stripe>
                <el-table-column prop="papername" label="问卷名称"></el-table-column>
                <el-table-column prop="classname" label="班级名称"></el-table-column>
                <el-table-column label="大纲名称">
                    <template #default="{ row }">
                        <div>
                            {{ row.outlines.map((el) => el.outlinename).join(" 、") }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="操作">
                    <template #default="{ row }">
                        <div>
                            <el-button type="text" @click="$router.push({ name: 'PapersEdit', params: { id: row._id } })">
                                编辑
                            </el-button>
                            <el-button type="text" @click="delPaperLoading(row._id)">
                                删除
                            </el-button>
                            <el-button type="text" @click="$router.push({ name: 'Release', params: { id: row._id } })">
                                发布
                            </el-button>
                            <el-button type="text" @click="$router.push({ name: 'AnswersIndex', params: { id: row._id } })">
                                查看答卷
                            </el-button>
                        </div>
                    </template>
                </el-table-column>
            </el-table>
        </el-card>
    </div>
</template>
<script>
import {mapActions} from 'vuex'
export default{
    data(){
        return{
            papers:[],
            loading :false,
        }
    },
    async created(){
        await this.getPapersLoading();
    },
    methods:{
        ...mapActions('papers',['getPapers','delPaper']),
        // 获取
        async getPapersLoading(){
            this.loading=true;
            try {
                const {data} = await this.getPapers();
                this.papers=data.result;
            } catch (error) {}
            this.loading=false;
        },
        // 删除
        async delPaperLoading(id){
            try {
                await this.$confirm("此操作将永久删除，确定删除吗?");
                this.loading=true;
                await this.delPaper(id);
                this.getPapersLoading();
            } catch (error) {}
            this.loading=false;
        },
    }
}
</script>